﻿using System;
using System.Collections.Generic;
using System.Text;

namespace EasyStudy.Logic
{
    public class EbbinghausTask
    {
        public EbbinghausTask()
        {
            finishPrecent = 0.0F;
            remindTimes = new List<DateTime>();
            subject = "PLEASE INSERT A SUBJECT.";
            comment = "YOU CAN ADD ANY COMMENT HERE.";
            nextIndex = 0;
        }

        public override string ToString()
        {
            StringBuilder sBuilder = new StringBuilder();
            sBuilder.AppendLine("subject:\t" + subject);
            sBuilder.AppendLine("comment:\t" + comment);
            sBuilder.AppendLine("create time:");
            sBuilder.AppendLine("\t" + CreateTime.ToString(EbbTaskDBMgr.DATETIME_FORMAT));
            sBuilder.AppendLine("last update time:");
            sBuilder.AppendLine("\t" + UpdateTime.ToString(EbbTaskDBMgr.DATETIME_FORMAT));
            sBuilder.AppendLine("next update time:");
            sBuilder.AppendLine("\t" + NextTime.ToString(EbbTaskDBMgr.DATETIME_FORMAT));
            sBuilder.AppendLine("remind list:");
            foreach (DateTime remindTime in RemindTimes)
            {
                sBuilder.AppendLine("\t" + remindTime.ToString(EbbTaskDBMgr.DATETIME_FORMAT));
            }

            return sBuilder.ToString();
        }

        #region Properties
        public string ID
        {
            get { return id; }
            set { id = value; }
        }

        public int NextIndex
        {
            get { return nextIndex; }
            set 
            { 
                nextIndex = value;
            }
        }

        public DateTime CreateTime
        {
            get { return createTime; }
            set { createTime = value; }
        }

        public DateTime UpdateTime
        {
            get { return updateTime; }
            set { updateTime = value; }
        }

        public DateTime NextTime
        {
            get { return nextTime; }
            set { nextTime = value; }
        }

        public List<DateTime> RemindTimes
        {
            get { return remindTimes; }
            set { remindTimes = value; }
        }

        public float FinishPrecent
        {
            get { return finishPrecent; }
            set { finishPrecent = value; }
        }

        public string Subject
        {
            get { return subject; }
            set 
            {
                subject = ReplaceAllQuotas(value); 
            }
        }

        public static string ReplaceAllQuotas(string sql)
        { 
            StringBuilder sBuilder = new StringBuilder();

            foreach(char c in sql.ToCharArray())
            {
                if (c == '"')
                {
                    sBuilder.Append("\"\"");
                }
                else {
                    sBuilder.Append(c);
                }
            }
            return sBuilder.ToString();
        }

        public string Comment
        {
            get { return comment; }
            set 
            {
                comment = ReplaceAllQuotas(value); 
            }
        }

        public string Type {
            get { return type; }
            set { type = value; }
        }
        #endregion

        #region Fields
        private List<DateTime> remindTimes;
        private DateTime createTime;
        private DateTime updateTime;
        private DateTime nextTime;
        private float finishPrecent;                  // 完成/总数 百分比
        private string comment;
        private string subject;
        private int nextIndex;                        // 此索引对应remindTimes
        private string type;                          // 任务的类型
        private string id;
        #endregion
    }
}
